﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using He.Web.UI;
using He.Common;

namespace He.Web.user
{
    public partial class reg_check : System.Web.UI.Page
    {
        public int status;
        protected void Page_Load(object sender, EventArgs e)
        {
            status = InputUtil.Get("status", 0);
        }

        protected void lbtnReSend_Click(object sender, EventArgs e)
        {
            Model.site_info SiteInfo = new BLL.site_info().GetModelByLang("cn");
            Model.webset SiteConfig = new BLL.webset().GetWebset();

            string user_name = InputUtil.Get("user_name");
            Model.member member = new BLL.member().GetModel(user_name);
            if (member != null)
            {
                if (member.reset_key != "" && member.reset_expires != "")
                {
                    //读取邮件模板
                    string body = MemberHelper.ReadTemplate("~/user/email/activate.html");
                    //替换模板标签
                    body = MemberHelper.ReplaceTemplate(body, member);
                    if (EmailHelper.SendEmail("用户激活", SiteConfig.email_id, CryptoHelper.DESDecrypt(SiteConfig.email_pwd), SiteConfig.email_smtpserver, member.user_name, member.email, "会员账号激活", body, true))
                    {
                        Response.Redirect("/user/reg_check.aspx?status=" + Enums.MemberStatus.Email验证.ToString() + "&user_name=" + Server.UrlEncode(member.user_name));
                    }
                    else
                    {
                        Response.Write("<script>alert('邮件发送失败，请重试')</script>");
                    }
                }
                else
                {
                    Response.Redirect("~/error.aspx?s=用户不在激活范围");
                }
            }
            else
            {
                Response.Redirect("~/error.aspx?s=用户不存在");
            }
        }
    }
}